package org.smart4j.framework;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.Proxy.AspectProxy;
import org.smart4j.framework.annotation.Aspect;
import org.smart4j.framework.annotation.Controller;

import java.lang.reflect.Method;

/**
 * ContrellerAspect
 *
 * @author sc
 * @date 2016-6-21
 */
@Aspect(Controller.class)
public class ContrellerAspect extends AspectProxy {

    private static final Logger LOGGER = LoggerFactory.getLogger(ContrellerAspect.class);

    private long begin;

    @Override
    public void before(Class<?> cls, Method method, Object[] params) throws Throwable {
        LOGGER.debug("---------begin---------");
        LOGGER.debug(String.format("Class: %s", cls.getName()));
        LOGGER.debug(String.format("Method: %s", method.getName()));
        begin = System.currentTimeMillis();

        System.out.println("------------begin----------");
        System.out.println(String.format("Class: %s", cls.getName()));
        System.out.println(String.format("Method: %s", method.getName()));
    }

    @Override
    public void after(Class<?> cls, Method method, Object[] params) throws Throwable {
        LOGGER.debug(String.format("time: %dms", System.currentTimeMillis() - begin));
        LOGGER.debug("---------end----------");

        System.out.println(String.format("time: %dms", System.currentTimeMillis() - begin));
        System.out.println("------------end----------");
    }
}
